/*
 * @Author: szx
 * @Date: 2022-06-13 14:35:39
 * @LastEditTime: 2022-06-13 14:53:48
 * @Description:
 * @FilePath: \leetcode\面试题\17\05\05.js
 */
/**
 * @param {string[]} array
 * @return {string[]}
 */
var findLongestSubarray = function (array) {
    const map = new Map();

    map.set(0, -1);
    let sum = 0,
        front = 0,
        end = 0;
    array.forEach((v, i) => {
        sum += v >= 'A' && v <= 'z' ? 1 : -1;
        if (map.has(sum)) {
            front = map.get(sum);
            end = i;
        } else map.set(sum, i);
    });
    return array.slice(front, end+1);
};
